<template>
  <div>
    <el-card>
      <el-tabs v-model="activeName">
        <el-tab-pane label="登录账户设置" name="first">
          <el-form ref="form" class="user-form" :model="form">
            <el-form-item label="姓名：" label-width="80px">
              <el-input v-model="form.username" />
            </el-form-item>
            <el-form-item label="密码：" label-width="80px">
              <el-input v-model="form.password" type="password" />
            </el-form-item>
            <el-form-item label-width="80px">
              <el-button type="primary" @click="save">更新</el-button>
              <el-button @click="$router.push('/employees')">取消</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情" name="second">
          <emp-info ref="empInfo" />
        </el-tab-pane>
        <el-tab-pane label="岗位信息" name="third">
          <job-info />
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { profile, setProfileAPI } from '@/api/employees'
import EmpInfo from './components/EmpInfo.vue'
import JobInfo from './components/JobInfo.vue'
export default {
  components: {
    EmpInfo,
    JobInfo
  },
  data() {
    return {
      activeName: 'first',
      form: {
        username: '',
        password: ''
      }
    }
  },
  async created() {
    const res = await profile(this.$route.params.id)
    this.form = res.data
    this.$refs.empInfo.userInfo = {
      ...res.data
    }
  },
  methods: {
    async save() {
      await setProfileAPI(this.form)
      this.$message.success('修改成功！')
      // 要退出
      this.$store.dispatch('user/logout')
    }
  }
}
</script>

<style lang="scss" scoped>

.user-form {
  width: 350px;
  margin: 50px auto;
}

</style>
